package com.stockz.ui.swing.charting.widget;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.DefaultComboBoxModel;

import com.stockz.core.util.SpringUtil;
import com.stockz.ui.swing.charting.painter.chart.StockChartPainter;
import com.stockz.ui.swing.charting.util.RepaintStockChartPanelUtil;
import com.stockz.ui.swing.charting.view.StockChartPanel;
import com.stockz.ui.swing.widget.JComboBox;

public class ChartTypeCombobox extends JComboBox {
	private static final long serialVersionUID = 6867171274365560371L;
	
	private final StockChartPanel stockChartPanel;
	
	public  ChartTypeCombobox(StockChartPanel stockChartPanel1) {
		this.stockChartPanel = stockChartPanel1;
		setModel(new DefaultComboBoxModel(SpringUtil.getBeansOfType(StockChartPainter.class).toArray()));
		setSelectedIndex(0);
		addItemListener(new ItemListener(){
			@Override
			public void itemStateChanged(ItemEvent e) {
				if(stockChartPanel != null){
					stockChartPanel.getStockChartPanelState().setStockChartPainter((StockChartPainter)getSelectedItem());
					RepaintStockChartPanelUtil.repaintStockChartPanel(stockChartPanel);
				}
			}
		});
	}
}
